$(function() {
	console.log("加载任务详情");
	$("#task_detail_c").empty();
	$("#task_command").empty();
	$("#task_plan_start_time").empty();
	var taskData = [];
	state = 0;
	$.ajax({
		type: "post",
		url: "getTaskByState",
		async: true,
		cache: false,
		datatype: "json",
		data: {
			state: state //传递参数状态，获取任务信息
		},
		success: function(data) {
			if(data.length > 0) {
				taskData = data[0];
			}
		},
		complete: function() {
			//showTaskInfo(taskData,tableId); //显示不同任务的列表信息
				if(taskData.length != 0) {
					var addHTML_d = "<p>" + taskData.taskContent + "</p>";
					var addHTML_c = "<p>" + taskData.taskComment + "</p>";
					$("#task_detail_c").append(addHTML_d);
					$("#task_command").append(addHTML_c);
					taskData.taskPlanStartTime = taskData.taskPlanStartTime.replace("T", " ");
					taskData.taskPlanEndTime = taskData.taskPlanEndTime.replace("T", " ");
					taskData.taskRealStartTime = taskData.taskRealStartTime.replace("T", " ");
					$("#task_plan_start_time").text(taskData.taskPlanStartTime);
					$("#task_plan_end_time").text(taskData.taskPlanEndTime);
					$("#task_real_start_time").text(taskData.taskRealStartTime);
					getAheadTask(taskData.taskId); //查找前序任务
					current_task_id = taskData.taskId;
				} else {
					$("#task_detail_c").append("没有任务！继续加油哦！");
				}
			}
});
});
function submitTask(taskId) {
	if(taskId == 0) {
		alert("当前没有任务，请不要提交");
	} else {
		$.ajax({
			url: "submitTask",
			data: {
				taskId: taskId,
				state:1
			},
			type: "post",
			dataType: "json",
			async: true,
			cache: false,
			success: function(data) {
				//data为服务器所返回的值
				if(data == 1) {
					$("#" + taskId).remove();
					alert("提交成功！");
					//loadTaskDetail();
				}
			},
			complete: function() { //在success之后就进行
				//操作
			}
		});
	}
}
/**
 * 通过当前的任务编号回去任务的前序任务
 * @param {Object} taskId
 */
function getAheadTask(taskId){
	$.ajax({
		type: "post",
		url: "getAheadTask",
		async: true,
		cache: false,
		data: {
			taskId: taskId
		},
		success: function(data) { //获取到前序任务的详情 
			if(data != 0) {
				$("#ahead_task_name").text(data.id.pmPhaseInfo.phaseName);
				$("#ahead_task_dept").text(data.id.pmPhaseInfo.motusDept.name);
				$("#ahead_plan_end_time").text(data.phasePlanEndTime);
				if(data.phaseState == -1) {
					$("#ahead_task_state").text("未开始");
				}
				if(data.phaseState == 0) {
					$("#ahead_task_state").text("进行中");
				}
				if(data.phaseState == 0) {
					$("#ahead_task_state").text("审批中");
				}
				if(data.phaseState == 0) {
					$("#ahead_task_state").text("已完成");
				}
			}
			if(data == 0) {
				$("#ahead_task_name").text("无前序任务！");
			}
		},
		complete: function() {
		}
	});
}
